package com.zhs.gccs.view.taskMap;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhs.gccs.BuildConfig;
import com.zhs.gccs.R;
import com.zhs.gccs.view.BaseView;

public class PageHeader extends BaseView implements View.OnClickListener{
    private View ll_export_feed_back;
    private TextView tv_title;
    private TextView tv_user;
    private View ll_exit;
    private String title;
    private String userName;
    private View iv_menu;

    public PageHeader(@NonNull Context context) {
        super(context);
    }

    public PageHeader(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PageHeader(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_view_header, this, true);
//        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomerLogo);
//        String title = typedArray.getString(R.styleable.CustomerInfoItem_preText);
//        typedArray.recycle();
        ll_export_feed_back = view.findViewById(R.id.ll_export_feed_back);
        tv_title = view.findViewById(R.id.tv_title);
        tv_user = view.findViewById(R.id.tv_user);
        ll_exit = view.findViewById(R.id.ll_exit);
        ll_export_feed_back.setOnClickListener(this);
        ll_exit.setOnClickListener(this);
        iv_menu = view.findViewById(R.id.iv_menu);
        iv_menu.setOnClickListener(this);
        iv_menu.setVisibility(BuildConfig.OFFLINE?GONE:VISIBLE);
    }

    public PageHeader setExportVisibility(boolean visiable) {
        ll_export_feed_back.setVisibility(visiable?VISIBLE:GONE);
        return this;
    }

    public PageHeader setUserName(String userName) {
        this.userName = userName;
        tv_user.setText(userName);
        return this;
    }


    public PageHeader setTitle(String title) {
        this.title = title;
        tv_title.setText(title);
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_export_feed_back:
                if(pageHeaderListener!=null)pageHeaderListener.exportFeedback();
                break;
            case R.id.ll_exit:
                if(pageHeaderListener!=null)pageHeaderListener.logout();
                break;
            case R.id.iv_menu:
                if(pageHeaderListener!=null)pageHeaderListener.openLeftMenu();
                break;
        }
    }


    private PageHeaderListener pageHeaderListener;

    public void setPageHeaderListener(PageHeaderListener pageHeaderListener) {
        this.pageHeaderListener = pageHeaderListener;
    }

    public interface PageHeaderListener{
        void logout();
        void exportFeedback();
        void openLeftMenu();
    }
}
